{include file='common/doc'}
</head>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto" style="display: none;">

        </div>
        <div class="layui-card-body">
            <table id="table_list" lay-filter="table_list"></table>
            <script type="text/html" id="buttonTpl">
                {{#  if(d.status == 1){ }}
                <button class="layui-btn layui-btn-xs">已审核</button>
                {{#  } else { }}
                <button class="layui-btn layui-btn-primary layui-btn-xs">未审核</button>
                {{#  } }}
            </script>
            <script type="text/html" id="sex">
                {{#  if(d.sex == 1){ }}
                <button class="layui-btn layui-btn-xs">男</button>
                {{#  } else { }}
                <button class="layui-btn layui-btn-primary layui-btn-xs">女</button>
                {{#  } }}
            </script>
            <script type="text/html" id="op_table">
                {{#  if(d.admin_id !==1){ }}
                <?php echo $operation['tool']; ?>
                {{#  } }}
            </script>
            <template id="table_toolbar">
                <div class="layui-btn-group">
                    <?php echo $operation['toolbar']; ?>
                </div>
            </template>
        </div>
    </div>
</div>
<template id="form_template" style="display: none">
    <form class="layui-form" id="form" lay-filter="form" action="" style="margin-top:10px;">
        <div class="layui-form-item">
            <label class="layui-form-label">昵称</label>
            <div class="layui-input-inline">
                <input type="text" name="admin_nickname" required lay-verify="required" lay-reqText="昵称不能为空"
                       lay-verType="tips"
                       placeholder="请输入昵称"
                       autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">昵称列:张三,李四</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">用户组</label>
            <div class="layui-input-inline">
                <select name="admin_group" lay-verify="">
                    <option value="">请选择</option>
                    {foreach $role as $key=>$vo }
                    <option value="{$vo['admin_group_id']}">{$vo['admin_group_name']}</option>
                    {/foreach}
                </select>
            </div>
            <div class="layui-form-mid layui-word-aux">必选项</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">账号</label>
            <div class="layui-input-inline">
                <input type="text" name="admin_account" required lay-verify="required" lay-reqText="账号不能为空"
                       lay-verType="tips"
                       placeholder="请收入账号"
                       autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">必填项 列:132324,abcsfd</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-inline">
                <input type="text" name="admin_passwd" required lay-verify="required" lay-reqText="密码不能为空"
                       lay-verType="tips"
                       placeholder="请输入密码"
                       autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">列:1324sdfs</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">确认密码</label>
            <div class="layui-input-inline">
                <input type="text" name="repasswd" required lay-verify="required" lay-reqText="昵称不能为空"
                       lay-verType="tips"
                       placeholder="请输入确认密码"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">性别</label>
            <div class="layui-input-inline">
                <input type="radio" name="sex" value="1" title="男" checked>
                <input type="radio" name="sex" value="2" title="女">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-inline">
                <input type="checkbox" name="status" lay-skin="switch" lay-text="已审核|禁用">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">描述</label>
            <div class="layui-input-block">
                <textarea name="remarks" placeholder="请输入描述内容" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="form_submit">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</template>
<script src="/layuiadmin/layui/layui.js"></script>
</body>
<script>
    layui.config({
        base: '/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index' ,'table'] ,function () {
        var $ = layui.$
            ,form = layui.form
            ,table = layui.table;
        table.render({
            elem: '#table_list'
            ,height: 'full-50'
            ,toolbar: '#table_toolbar'
            ,url: 'read' //数据接口
            ,page: true //开启分页
            ,limit:20
            ,cols: [
                [ //表头
                    {type: 'checkbox' ,fixed: 'left'} ,
                    {type: 'numbers' ,fixed: 'left'}
                    ,{field: 'admin_nickname' ,align: "center" ,title: '昵称'}
                    ,{field: 'admin_account' ,align: "center" ,title: '用户名'}
                    ,{field: 'addtime' ,title: '添加时间' ,sort: true}
                    ,{field: 'sex' ,title: '性别' ,align: "center" ,templet: '#sex'}
                    ,{field: 'status' ,title: '状态' ,align: "center" ,templet: '#buttonTpl'}
                    ,{field: 'remarks' ,title: '描述'}
                    ,{title: '操作' ,width: 150 ,align: 'center' ,fixed: 'right' ,toolbar: '#op_table'}
                ]
            ]
        });
        //头工具栏事件
        table.on('toolbar(table_list)' ,function (obj) {
            let event = obj.event;
            var checkStatus = table.checkStatus(obj.config.id);
            if (event == 'add') {
                lgp_open();
            }

        });

        function lgp_open(data={}){
            layer.open({
                type: 1 ,
                title: '用户编辑' ,
                area: ['auto'] ,
                content: $('#form_template').html() ,
                success: function (lay ,index) {
                    let url = 'add';
                    form.render();
                   if (JSON.stringify(data)!=='{}'){
                       form.val('form' ,data);
                        url = 'upd';
                   }
                    form.on('submit(form_submit)' ,function (res) {
                        Object.assign(data, res.field);
                        let status = request({'url': url, 'data': data});
                        if (status) {
                            layer.close(index);
                            table.reload('table_list');
                        }
                        return false;
                    });
                }
            })
        }
        table.on('tool(table_list)' ,function (obj) {
            let event = obj.event;
            console.log(event);
            if (event == 'upd') {
                lgp_open(obj.data);
            }

            if (event == 'del') {
                let status = request({'url': 'del', 'data': {'admin_id':obj.data['admin_id']}});
                if (status) {
                    obj.del();
                }
            }
        });
        /*搜索*/
        form.on('submit(search)' ,function (obj) {
            table.reload('table_list' ,{
                method: 'get' ,
                where: obj.field //设定异步数据接口的额外参数
            });
            return false;
        });
    });
</script>
</html>

